﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Sintaxe;
using Sintaxe.Instrucoes;
using ProcUtils;


namespace XYSC_1
{
    public partial class frmEditXYSC1 : EditForm
    {
        public frmEditXYSC1(IProcessador prmProc, Instrucao prmInst) : base(prmProc, prmInst)
        {
            InitializeComponent();
        }


        private void Form2_Load(object sender, EventArgs e)
        {
            List<string> ll;

            // encher combo boxes

            ll = (RefProc as XYSC1_V2).RegsGer.Lexemas().ToList();
            ll.Insert(0, " ");
            cmbRegD.DataSource = ll;

            ll = (RefProc as XYSC1_V2).RegsGer.Lexemas().ToList();  // precisa nova cópia. Sem isso, os dois cmb mostram sempre o mesmo reg.
            ll.Insert(0, " ");
            cmbRegF.DataSource = ll;

            ll = (RefProc as XYSC1_V2)._Mnemos.Lexemas().ToList();
            ll.AddRange(Diretor.Diretivas.Lexemas().ToList());
            ll.Insert(0, " ");
            cmbOp.DataSource = ll;


            // receber atributos da instrução --------------------------------------
            //

            // Atributo Categoria Instrucao. Mapear do char para string :-)
            var ci = from string Item in cmbCatI.Items
                     where Item[0] == (_instAtual as IM_XYSC1_V2).CatI
                     select Item;
            cmbCatI.Text = ci.First<string>();  // deve causar On_SelectedIndexChanged

            // Atributo Operacao
            cmbOp.Text = (_instAtual as IM_XYSC1_V2).Operacao;

            // Atributos registradores
            cmbRegD.Text = (_instAtual as IM_XYSC1_V2).RegDest;
            cmbRegF.Text = (_instAtual as IM_XYSC1_V2).RegFont;

            // Atributo condicao
            cmbCond.Text = (_instAtual as IM_XYSC1_V2).Condicao;

            // Atributos valor imediato
            txtImediato.Text = (_instAtual as IM_XYSC1_V2).Imediato;

            // Atributo comentário
            txtCom.Text = (_instAtual as IM_XYSC1_V2).Comentario;

        }



        private void btnEsc_Click(object sender, EventArgs e)
        {
            Close(); // nao modificar parametro out
        }


        private void btnOK_Click(object sender, EventArgs e)
        {
            // transportar os valores para o atributo out
            (_instAtual as IM_XYSC1_V2).CatI = cmbCatI.Text[0];
            (_instAtual as IM_XYSC1_V2).Rotulo = txtRotulo.Text;
            (_instAtual as IM_XYSC1_V2).Operacao = cmbOp.Text;
            (_instAtual as IM_XYSC1_V2).RegDest = cmbRegD.Text;
            (_instAtual as IM_XYSC1_V2).RegFont = cmbRegF.Text;
            (_instAtual as IM_XYSC1_V2).Condicao = cmbCond.Text;
            (_instAtual as IM_XYSC1_V2).Imediato = txtImediato.Text;
            (_instAtual as IM_XYSC1_V2).Comentario = txtCom.Text;

            // pronto
            this.Close();
        }



    }
}
